﻿using System.Data.Entity.ModelConfiguration;
using BeautyTech.Core.Domain.Security;

namespace BeautyTech.Data.Configuration.Security
{
    public class UserConfiguration : EntityTypeConfiguration<User>
    {
        public UserConfiguration()
        {
            this.Property(p => p.Id).HasColumnOrder(0);

            this.Property(p => p.UserName)
                .IsRequired().HasMaxLength(200);

            this.Property(p => p.FirstName)
                .IsRequired().HasMaxLength(75);

            this.Property(p => p.LastName)
                .IsRequired().HasMaxLength(75);

            this.Property(p => p.Email)
                .IsRequired().HasMaxLength(80);

            this.HasMany(a => a.Roles)
                .WithMany(b => b.Users).Map(m =>
                    {
                        m.MapLeftKey("UserId");
                        m.MapRightKey("RoleId");
                        m.ToTable("webpages_UsersInRoles");
                    });

        }
    }
}
